<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{$id}</title>
    <include file="Public:header" />
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerButton.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerRadio.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script> 
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerTip.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script> 
    <script src="__PUBLIC__/lib/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/jquery-validation/messages_cn.js" type="text/javascript"></script>

    <script type="text/javascript"> 
        var groupicon = "__PUBLIC__/lib/ligerUI/skins/icons/communication.gif";
         var saveurl='__URL__/insert/';
        $(function ()
        {
            $.metadata.setType("attr", "validate");
            
            //创建表单结构
            var mainform = $("#detailform");
              mainform.ligerForm({
                inputWidth: 170, labelWidth: 90, space: 40,
                fields: [
                { name: "id", type: "hidden" },
                { display: "名称", name: "name", newline: true, type: "text", validate: { required: true,minlength:3 }, group: "基础信息", groupicon: groupicon}, 
                { display: "上级", name: "pid", newline: true, type: "select", comboboxName: "pid1", options: { valueFieldID: "pid",data:<php>echo json_encode($list);</php>} },
                { display: "状态", name: "status", newline: true, type: "select", comboboxName: "status1", options: {valueFieldID: "status",data:[{text:"启用",id:"1"},{text:"禁用",id:"0"}]}},
                { display: "备注", name: "remark", newline: true, type: "textarea",width:400}
                ]
            });

            	var dataurl='__URL__/getById/id/'+{$id};
                $.get(dataurl,function(data){
                     var currentdata=eval("("+data+")");
                	 loadform(mainform,{},currentdata);
                 });	
           
            var validator = $("#detailform").validate({
                //调试状态，不会提交数据的
                debug: false,
                errorPlacement: function (lable, element)
                {

                    if (element.hasClass("l-textarea"))
                    {
                        element.addClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field"))
                    {
                        element.parent().addClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                    $(element).attr("title", lable.html()).ligerTip();
                },
                success: function (lable)
                {
                    var element = $("#" + lable.attr("for"));
                    if (element.hasClass("l-textarea"))
                    {
                        element.removeClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field"))
                    {
                        element.parent().removeClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                },
                submitHandler: function ()
                {
                    alert("Submitted!");
                }
            }); 
        }); 
        function loadform(mainform, options,data)
        {
        	var preID = options.preID || "";
            //根据返回的属性名，找到相应ID的表单元素，并赋值
       //     $.ligerDialog.alert('选择的是' +data.name);
            for (var p in data)
            {
                var ele = $("[name=" + (preID + p) + "]", mainform);
                //针对复选框和单选框 处理
                if (ele.is(":checkbox,:radio"))
                {
                    ele[0].checked = data[p] ? true : false;
                }
                else
                {
                    ele.val(data[p]);
                }
            }
            //下面是更新表单的样式
          var managers = $.ligerui.find($.ligerui.controls.Input);
            for (var i = 0, l = managers.length; i < l; i++)
            {
                //改变了表单的值，需要调用这个方法来更新ligerui样式
              var o = managers[i];
                o.updateStyle();
                if (managers[i] instanceof $.ligerui.controls.TextBox)
                    o.checkValue();
            }
        }//end function loadform
        function f_subset()
        {
            return $("#detailform").serialize();
        }
        
        function f_save(){
         	 $.post('__URL__/edit/',$("#detailform").serialize(),function(data){
         		LG.showMessage(data, function () { 
        			window.parent.grid.loadData();
                    window.parent.mydialog.close(); //要先刷新表格,再关闭窗口,否则表格不会刷新 
                });
       	 });
        }
    </script> 

</head>
<body style="padding:10px"> 
    <form id="detailform">
    </form> 
 </body>
</html>